/**
 * 创建用户
 * @returns
 */
function createUserList() {
  return [
    {
      userID: 1,
      username: 'admin',
      password: '123456',
      desc: '平台管理员',
      roles: ['平台管理员'],
      button: ['curse.detail'],
      routes: ['User', 'Acl', 'Product', 'Trademark'],
      token: 'Admin Token',
    },
    {
      userID: 2,
      username: 'test',
      password: '111111',
      desc: '测试',
      roles: ['测试'],
      button: ['curse.detail'],
      routes: ['home'],
      token: 'Admin Token',
    },
  ];
}

export default [
  //用户登录
  {
    url: '/api/user/login',
    method: 'post',
    response: ({ body }) => {
      const { username, password } = body;
      const checkUser = createUserList().find(
        (item) => item.username === username && item.password === password,
      );

      if (!checkUser) {
        return {
          code: 201,
          data: {
            message: '账号或者密码不正确',
          },
        };
      }

      const { token } = checkUser;
      return {
        code: 401,
        data: {
          token,
        },
      };
    },
  },
  //获取用户信息
  {
    url: '/api/user/info',
    method: 'get',
    response: ({ request }) => {
      console.log('🚀 ~ file: user.ts:64 ~ request:', request);
      const token = 'Admin Token';
      const checkUser = createUserList().find((item) => item.token === token);
      if (!checkUser) {
        return {
          code: 201,
          data: {
            message: '获取用户信息失败',
          },
        };
      }

      return {
        code: 200,
        data: checkUser,
      };
    },
  },
];
